package main.number;

import org.junit.Test;

import java.math.BigDecimal;

/**
 * Created by ChengGM on 2016/12/22.
 */
public class BigDecimalTest {
    @Test
    public void test1(){
        String a = new BigDecimal(23.456).setScale(1,BigDecimal.ROUND_DOWN)+"";
        int b = new BigDecimal(23.456).intValue();
        BigDecimal c = new BigDecimal(23.456).setScale(2,BigDecimal.ROUND_HALF_UP);
        System.out.println(a + "   "+ b + " " +c.toString() );
    }
    @Test
    public void test2(){
        int a = new BigDecimal(23).setScale(2,BigDecimal.ROUND_HALF_UP).intValue();
        System.out.println(a);

    }
    @Test
    public void test3(){
        BigDecimal a = new BigDecimal(2300).multiply(new BigDecimal(100)).setScale(2,BigDecimal.ROUND_HALF_UP);
        System.out.println(a+"%");

        String b =new BigDecimal((new Long(1000)).doubleValue()).multiply(new BigDecimal(100)).setScale(2, 4) + "%";
        System.out.println(b);

    }
}
